﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DBLibrary;

[TableMap("KeyFile")]
public class KeyDetail
{
    private string mKeyId = string.Empty;
    [ColumnMap("KeyId")]
    public string KeyId
    {
        get { return mKeyId; }
        set
        {
            if (!string.IsNullOrEmpty(mKeyId))
            {
                throw new Exception("Can't set KeyID value!");
            }
            mKeyId = value;
        }
    }

    [ColumnMap("Content")]
    public string Content
    {
        get;
        set;
    }

    public KeyContent KeyContent { 
        get { return KeyHelper.GenerateKeyContent(Content); }
        set { Content = KeyHelper.GenerageContentString(value); }
    }

    private int mUsageTypeInt = -1;
    [ColumnMap("Type")]
    public int UsageTypeInt
    {
        get { return mUsageTypeInt; }
        set
        {
            if (mUsageTypeInt >= 0)
            {
                throw new Exception("Can't set UsageTypeInt value!");
            }
            mUsageTypeInt = value;
        }
    }

    public KeyUsageType UsageType { get { return (KeyUsageType)UsageTypeInt; } }

    [ColumnMap("IsInUse")]
    public bool  IsInUse { get; set; }

    [ColumnMap("DBPre")]
    public string DBPre { get; set; }
}